package com.piggy.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.sys.bo.SysSettingEditBo;
import com.piggy.sys.bo.SysSettingQueryBo;
import com.piggy.sys.service.ISysSettingService;
import com.piggy.sys.vo.SysSettingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 运营系统设置Controller
 *
 * @author piggy
 * @date 2023-11-13
 */
@Api(value = "运营系统设置控制器", tags = {"运营系统设置管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/setting")
public class SysSettingController extends BaseController {

    private final ISysSettingService iSysSettingService;

    /**
     * 查询运营系统设置列表
     */
    @ApiOperation("查询运营系统设置列表")
    //@SaCheckPermission("sys:setting:list")
    @GetMapping("/list")
    public TableDataInfo<SysSettingVo> list(@Validated SysSettingQueryBo bo) {
        return iSysSettingService.queryPageList(bo);
    }

    /**
     * 获取运营系统设置详细信息
     */
    @ApiOperation("获取运营系统设置详细信息")
    //@SaCheckPermission("sys:setting:query")
    @GetMapping("/{id}")
    public R<SysSettingVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iSysSettingService.queryById(id));
    }

    /**
     * 新增运营系统设置
     */
    @ApiOperation("新增运营系统设置")
    //@SaCheckPermission("sys:setting:add")
    @Log(title = "运营系统设置", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<SysSettingVo> add(@Validated @RequestBody SysSettingEditBo bo) {
        return R.ok(iSysSettingService.insertByAddBo(bo));
    }

    /**
     * 修改运营系统设置
     */
    @ApiOperation("修改运营系统设置")
    //@SaCheckPermission("sys:setting:edit")
    @Log(title = "运营系统设置", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<SysSettingVo> edit(@Validated @RequestBody SysSettingEditBo bo) {
        return R.ok(iSysSettingService.updateByEditBo(bo));
    }

    /**
     * 删除运营系统设置
     */
    @ApiOperation("删除运营系统设置")
    //@SaCheckPermission("sys:setting:remove")
    @Log(title = "运营系统设置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iSysSettingService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
